#include <stdio.h>

// 函数的声明不需要函数体, 函数的声明不加 extern 也是可以的

void printf_pyramid(int n);

void swap_number(int a, int b);

void swap_address(int *a_address, int *b_address);

int main() {
    // 函数的作用: 减少重复代码块, 代码模块清晰

    // 函数定义时()里面的参数称为形参, 形参只有函数被调用时才会分配内存空间

    // 函数的返回值小于等于四个字节时, 返回值存储在寄存器中, 返回值大于四字节将存储在内存中

    // 交换形参的值
    int a = 100;
    int b = 200;
    // 形参的值传递不会改变实参的值
    swap_number(a, b);
    printf("no in swap_number a = %d\n", a);    // 100
    printf("no in swap_number b = %d\n", b);    // 200
    printf("\n");

    // 实参的地址传递会改变实参的值
    int *a_address = &a;
    int *b_address = &b;
    swap_address(a_address, b_address);
    printf("no in swap_address *a_address = %d\n", *a_address); // 200
    printf("no in swap_address *b_address = %d\n", *b_address); // 100
    printf("\n");

    // swap_address 实际更改的值是 a 和 b 的值
    printf("a = %d\n", a);  // 200
    printf("b = %d\n", b);  // 100
    printf("\n");

    // 打印 n 行金字塔
    int n;
    scanf("%d", &n);
    printf_pyramid(n);

    return 0;
}

void printf_pyramid(int n) {
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (i <= j) {
                printf(" *");
            } else {
                printf(" ");
            }
        }

        printf("\n");
    }
    printf("\n");
}

void swap_number(int a, int b) {
    int temp;

    temp = a;
    a = b;
    b = temp;

    printf("in swap_number a = %d\n", a);   // 200
    printf("in swap_number b = %d\n", b);   // 100
    printf("\n");
}

void swap_address(int *a_address, int *b_address) {
    int temp = 0;

    temp = *a_address;
    *a_address = *b_address;
    *b_address = temp;

    printf("in swap_address a = %d\n", *a_address); // 200
    printf("in swap_address b = %d\n", *b_address); // 100
    printf("\n");
}